package xj.graph2d.template.uml;

import xj.graph2d.AbstractModelListener;
import xj.graph2d.DrawShape;
import xj.graph2d.DrawShapeConstants;
import xj.graph2d.GraphNodeBase;
import xj.graph2d.shapes.uml.UMLUtil;
import xj.model.uml.UseCase;

public class UMLUseCaseModelListener extends AbstractModelListener {

  public UMLUseCaseModelListener() {
  }

  public UMLUseCaseModelListener(Object model, DrawShape shape) {
    super(model, shape);
  }

  @Override
  public void updateModel() {
    if (shape instanceof GraphNodeBase && model instanceof UseCase) {
      GraphNodeBase ucnode = (GraphNodeBase) shape;
      UseCase ucmodel = (UseCase) model;
      String name = UMLUtil.getName(ucnode, DrawShapeConstants.ROLE_NODE_LABEL);
      String st = UMLUtil.getStereotypes(ucnode,
	  DrawShapeConstants.ROLE_NODE_LABEL);
      if (name != null) {
	ucmodel.setName(name);
      }
      ucmodel.setStereotypes(st);
    }
  }

  @Override
  public void updateShape() {
    if (shape instanceof GraphNodeBase && model instanceof UseCase) {
      GraphNodeBase ucnode = (GraphNodeBase) shape;
      UseCase ucmodel = (UseCase) model;
      String name = ucmodel.getName();
      String st = ucmodel.getStereotypeString();
      if (name != null) {
	UMLUtil.setName(ucnode, DrawShapeConstants.ROLE_NODE_LABEL, name);
	// ucnode.setLabel(name);
      }
      UMLUtil.setStereotypes(ucnode, DrawShapeConstants.ROLE_NODE_LABEL, st);
    }
  }

}
